package com.mymvc.controller.restful;

import com.mymvc.vo.User;
import com.mymvc.vo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: UserController
 * Package: com.mymvc.controller.restful
 * Description:
 *
 * @Author 刘英杰
 * @Create 2025/2/9 15:08
 * @Version 1.0
 */

@Controller
@RequestMapping("/user")
public class UserController {
    @GetMapping("/{id}")
    public @ResponseBody User findById(@PathVariable("id") Integer uid) {
        return new User(uid,"张三","123");
    }

    @PostMapping()
    public String saveUser(@RequestBody User user) {
        System.out.println("已保存");
        System.out.println(user);
        return "success";
    }


    @GetMapping("/restful")
    public String restful() {
        return "restful";
    }

    @PutMapping()
    public String updateUser(User user) {
        System.out.println("更新用户的信息");//模拟将用户信息更新到数据库
        System.out.println(user);
        return "success";
    }

    @DeleteMapping("/${id}")
    public String deleteUser(@PathVariable("id") Integer uid) {
        System.out.println("删除用户的信息:"+uid);
        return "success";
    }
}
